<?php

/**
 *	Entry name：项目名称
 *	Description：项目说明
 *	Author：ZERO-ART
 *	Author Url：http://www.lykep.com
 * 	Contact：708298599  656001878
 *	2019-11-07 15:16:44
 */

/**
 * 初始化采集器一
 * @param [string]  $url  [请求地址]
 * @param integer $red  [是否开启重定向 0关闭 1开启]
 * @param integer $time [请求等待时间]
 */
function LoadOne($_url, $_red = 1, $_time = 10)
{
    $user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"; //UA
    $ch = curl_init(); //启动会话
    curl_setopt($ch, CURLOPT_HEADER, 0); //不返回 header 部分
    curl_setopt($ch, CURLOPT_URL, $_url); //访问地址
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); // 伪造ua
    curl_setopt($ch, CURLOPT_REFERER, $_url); //伪装请求来源 URL
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //参数为1表示传输数据，为0表示直接输出显示
    $ip = mt_rand(48, 140) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240) . "." . mt_rand(10, 240); //随机 ip
    $httpheader[] = 'CLIENT-IP:' . $ip;
    $httpheader[] = 'X-FORWARDED-FOR:' . $ip;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader); //附加协议头
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $_red); //支持重定向
    curl_setopt($ch, CURLOPT_AUTOREFERER, $_red); //重定向时，自动设置header的Referer信息           
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
    curl_setopt($ch, CURLOPT_TIMEOUT, $_time); //设置curl允许执行的最长秒数
    curl_setopt($ch, CURLOPT_ENCODING, ''); //解决网页乱码问题
    $content = trim(curl_exec($ch)); //移除两边空白或其他字符
    curl_close($ch); //关闭会话
    return $content; //返回数据
}

/**
 * 伦理禁片过滤
 * @param [string]  $obj [调用方法名]]
 * @param [array] 	$val [GET参数值]
 * @param [string] 	$url [请求地址]
 */
function ethicfilter($auth = [])
{
    // if (in_array()) {
    //     # code...
    // }
}

/**
 * 初始化请求地址
 * @param [string]  $obj [调用方法名]]
 * @param [array] 	$val [GET参数值]
 * @param [string] 	$url [请求地址]
 */
function InitUrl($obj, $val = [], $url = 'http://json.apibdzy.com/inc/feifei/')
{
    //判断调用方法
    switch ($obj) {
        case 'getDyList': //获取电影列表
            // dump($val);
            if (trim($val['cat']) === "all") {
                $val['cat'] = 5;
            }
            //请求参数拼接
            $v1 = '?cid=' . $val['cat'] . '&p=' . $val['page'];
            break;
        case 'getDsList': //获取电视列表
            if (trim($val['cat']) === "all") {
                $val['cat'] = 12;
            }
            //请求参数拼接
            $v1 = '?cid=' . $val['cat'] . '&p=' . $val['page'];
            break;
        case 'getDmList': //获取动漫列表
            if (trim($val['cat']) === "all") {
                $val['cat'] = 23;
            }
            //请求参数拼接
            $v1 = '?cid=' . $val['cat'] . '&p=' . $val['page'];
            break;
        case 'getZyList': //获取综艺列表
            if (trim($val['cat']) === "all") {
                $val['cat'] = 3;
            }
            //请求参数拼接
            $v1 = '?cid=' . $val['cat'] . '&p=' . $val['page'];
            break;
        default:
            $v1 = '';
            break;
    }
    //判断是否为空
    if (!empty($v1)) {
        //拼接地址
        $v2 = $url . $v1;
        //输出地址
        return $v2;
    } else {
        return;
    }
}

/**
 * 初始化返回数据
 */
function InitData()
{
    $data = [
        "code" => "200",
        "data" => [],
        "nav" => [],
        "col" => [],
        "page" => [],
        "type" => '',
        "consume" => 0
    ];
    return $data;
}

/**
 * 获取电影列表
 * @param array  $_get 参数
 * @param int $num 输出影片数量 可为空 大于零生效
 */
function getDyList($_get = [], $_num = 0)
{
    //获取采集地址
    $_url = InitUrl("getDyList", $_get);
    //判断地址是否存在
    if (empty($_url)) {
        return;
    }
    $json_data = InitData();
    //获取网页源码
    $html = LoadOne($_url);
    $code = json_decode($html, true);
    // exit;
    // 判断是否采集成功
    if (isset($code['status']) == 200) {
        // 影片信息
        $i = 0;
        foreach ($code['data'] as $key => $value) {
            if ($value['vod_cid'] != 27 && $value['vod_cid'] != 28 && $value['vod_cid'] != 29 && $value['vod_cid'] != 30 && $value['vod_cid'] != 31 && $value['vod_cid'] != 32 && $value['vod_cid'] != 33 && $value['vod_cid'] != 34 && $value['vod_cid'] != 35) {
                $json_data['data'][$i]['vod_id'] = $i + 1;
                $json_data['data'][$i]['vod_pic'] = $value['vod_pic'];
                $kval = base64_encode($value['vod_cid'] . '-' . $code['page']['pageindex'] . '-' . $value['vod_id']);
                $kval = str_replace('=', "", $kval);
                $json_data['data'][$i]['vod_url'] = '/zy/' . $kval . '.html';
                $json_data['data'][$i]['vod_pay'] = '';
                $json_data['data'][$i]['vod_year'] = $value['vod_year'];
                $json_data['data'][$i]['vod_score'] = '';
                $json_data['data'][$i]['vod_hint'] = $value['vod_continu'];
                $json_data['data'][$i]['vod_title'] = $value['vod_name'];
                $json_data['data'][$i]['vod_actor'] = $value['vod_actor'];
                $i++;
            }
        }

        // 类型信息
        $json_data['nav'][0]['name'] = "按类型：";
        $json_data['nav'][0]['data'] = [
            ['id' => 5, 'name' => "动作片"],
            ['id' => 6, 'name' => "喜剧片"],
            ['id' => 7, 'name' => "爱情片"],
            ['id' => 8, 'name' => "科幻片"],
            ['id' => 9, 'name' => "恐怖片"],
            ['id' => 10, 'name' => "剧情片"],
            ['id' => 11, 'name' => "战争片"],
            ['id' => 16, 'name' => "犯罪片"],
            ['id' => 18, 'name' => "记录片"],
            ['id' => 17, 'name' => "其他片"],
        ];

        $col_v1 = [['id' => 'rankhot', 'name' => '独家资源']];
        // //专题
        $json_data['col'] = $col_v1;
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" => $code['page']['pagecount'],
            "pagesize" => $code['page']['pagesize'],
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '电影列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        //输出影片json数据
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //404数据为空
        $json_data['data'] = [];
        $json_data['nav'] = [];
        $json_data['col'] = [];
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" =>  '0',
            "pagesize" => 0,
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '电影列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}


/**
 * 获取电视列表
 * @param [type]  $url [电视列表地址]
 * @param integer $num [输出影片数量 可为空 大于零生效]
 */
function getDsList($_get, $_num = 0)
{
    //获取采集地址
    $_url = InitUrl("getDsList", $_get);
    //判断地址是否存在
    if (empty($_url)) {
        return;
    }
    $json_data = InitData();
    //获取网页源码
    $html = LoadOne($_url);
    $code = json_decode($html, true);
    // 判断是否采集成功
    if (isset($code['status']) == 200) {
        // 影片信息
        $i = 0;
        foreach ($code['data'] as $key => $value) {
            if ($value['vod_cid'] != 27 && $value['vod_cid'] != 28 && $value['vod_cid'] != 29 && $value['vod_cid'] != 30 && $value['vod_cid'] != 31 && $value['vod_cid'] != 32 && $value['vod_cid'] != 33 && $value['vod_cid'] != 34 && $value['vod_cid'] != 35) {
                $json_data['data'][$i]['vod_id'] = $i + 1;
                $json_data['data'][$i]['vod_pic'] = $value['vod_pic'];
                $kval = base64_encode($value['vod_cid'] . '-' . $code['page']['pageindex'] . '-' . $value['vod_id']);
                $kval = str_replace('=', "", $kval);
                $json_data['data'][$i]['vod_url'] = '/zy/' . $kval . '.html';
                $json_data['data'][$i]['vod_pay'] = '';
                $json_data['data'][$i]['vod_year'] = $value['vod_year'];
                $json_data['data'][$i]['vod_score'] = '';
                $json_data['data'][$i]['vod_hint'] = $value['vod_continu'];
                $json_data['data'][$i]['vod_title'] = $value['vod_name'];
                $json_data['data'][$i]['vod_actor'] = $value['vod_actor'];
                $i++;
            }
        }

        // 类型信息
        $json_data['nav'][0]['name'] = "按类型：";
        $json_data['nav'][0]['data'] = [
            ['id' => 12, 'name' => "国产剧"],
            ['id' => 13, 'name' => "港台剧"],
            ['id' => 14, 'name' => "日韩剧"],
            ['id' => 15, 'name' => "欧美剧"],
            ['id' => 36, 'name' => "海外剧"],
        ];

        $col_v1 = [['id' => 'rankhot', 'name' => '独家资源']];
        // //专题
        $json_data['col'] = $col_v1;
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" => $code['page']['pagecount'],
            "pagesize" => $code['page']['pagesize'],
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '电视列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        //输出影片json数据
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //404数据为空
        $json_data['data'] = [];
        $json_data['nav'] = [];
        $json_data['col'] = [];
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" => '0',
            "pagesize" => 0,
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '电视列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}


/**
 * 获取动漫列表
 * @param array  $_get 参数
 * @param int $num 输出影片数量 可为空 大于零生效
 */
function getDmList($_get, $_num = 0)
{
    //获取采集地址
    $_url = InitUrl("getDmList", $_get);
    //判断地址是否存在
    if (empty($_url)) {
        return;
    }
    $json_data = InitData();
    //获取网页源码
    $html = LoadOne($_url);
    $code = json_decode($html, true);
    // 判断是否采集成功
    if (isset($code['status']) == 200) {
        // 影片信息
        $i = 0;
        foreach ($code['data'] as $key => $value) {
            if ($value['vod_cid'] != 27 && $value['vod_cid'] != 28 && $value['vod_cid'] != 29 && $value['vod_cid'] != 30 && $value['vod_cid'] != 31 && $value['vod_cid'] != 32 && $value['vod_cid'] != 33 && $value['vod_cid'] != 34 && $value['vod_cid'] != 35) {
                $json_data['data'][$i]['vod_id'] = $i + 1;
                $json_data['data'][$i]['vod_pic'] = $value['vod_pic'];
                $kval = base64_encode($value['vod_cid'] . '-' . $code['page']['pageindex'] . '-' . $value['vod_id']);
                $kval = str_replace('=', "", $kval);
                $json_data['data'][$i]['vod_url'] = '/zy/' . $kval . '.html';
                $json_data['data'][$i]['vod_pay'] = '';
                $json_data['data'][$i]['vod_year'] = $value['vod_year'];
                $json_data['data'][$i]['vod_score'] = '';
                $json_data['data'][$i]['vod_hint'] = $value['vod_continu'];
                $json_data['data'][$i]['vod_title'] = $value['vod_name'];
                $json_data['data'][$i]['vod_actor'] = $value['vod_actor'];
                $i++;
            }
        }
        // 类型信息
        $json_data['nav'][0]['name'] = "按类型：";
        $json_data['nav'][0]['data'] = [
            ['id' => 23, 'name' => "国产动漫"],
            ['id' => 24, 'name' => "日本动漫"],
            ['id' => 25, 'name' => "欧美动漫"],
            ['id' => 26, 'name' => "海外动漫"],
        ];

        $col_v1 = [['id' => 'rankhot', 'name' => '独家资源']];
        // //专题
        $json_data['col'] = $col_v1;
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" => $code['page']['pagecount'],
            "pagesize" => $code['page']['pagesize'],
        ];

        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '动漫列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        //输出影片json数据
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //404数据为空
        $json_data['data'] = [];
        $json_data['nav'] = [];
        $json_data['col'] = [];
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" =>  '0',
            "pagesize" => 0,
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '动漫列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}


/**
 * 获取综艺列表
 * @param array  $_get 参数
 * @param int $num 输出影片数量 可为空 大于零生效
 */
function getZyList($_get, $_num = 0)
{
    //获取采集地址
    $_url = InitUrl("getZyList", $_get);
    //判断地址是否存在
    if (empty($_url)) {
        return;
    }
    $json_data = InitData();
    //获取网页源码
    $html = LoadOne($_url);
    $code = json_decode($html, true);
    // 判断是否采集成功
    if (isset($code['status']) == 200) {
        // 影片信息
        $i = 0;
        foreach ($code['data'] as $key => $value) {
            if ($value['vod_cid'] != 27 && $value['vod_cid'] != 28 && $value['vod_cid'] != 29 && $value['vod_cid'] != 30 && $value['vod_cid'] != 31 && $value['vod_cid'] != 32 && $value['vod_cid'] != 33 && $value['vod_cid'] != 34 && $value['vod_cid'] != 35) {
                $json_data['data'][$i]['vod_id'] = $i + 1;
                $json_data['data'][$i]['vod_pic'] = $value['vod_pic'];
                $kval = base64_encode($value['vod_cid'] . '-' . $code['page']['pageindex'] . '-' . $value['vod_id']);
                $kval = str_replace('=', "", $kval);
                $json_data['data'][$i]['vod_url'] = '/zy/' . $kval . '.html';
                $json_data['data'][$i]['vod_pay'] = '';
                $json_data['data'][$i]['vod_year'] = $value['vod_year'];
                $json_data['data'][$i]['vod_score'] = '';
                $json_data['data'][$i]['vod_hint'] = $value['vod_continu'];
                $json_data['data'][$i]['vod_title'] = $value['vod_name'];
                $json_data['data'][$i]['vod_actor'] = $value['vod_actor'];
                $i++;
            }
        }

        // 类型信息
        $json_data['nav'][0]['name'] = "按类型：";
        $json_data['nav'][0]['data'] = [
            ['id' => 19, 'name' => "大陆综艺"],
            ['id' => 20, 'name' => "日韩综艺"],
            ['id' => 21, 'name' => "港台综艺"],
            ['id' => 22, 'name' => "欧美综艺"],
        ];

        $col_v1 = [['id' => 'rankhot', 'name' => '独家资源']];
        // //专题
        $json_data['col'] = $col_v1;
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" => $code['page']['pagecount'],
            "pagesize" => $code['page']['pagesize'],
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '综艺列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        //输出影片json数据
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //404数据为空
        $json_data['data'] = [];
        $json_data['nav'] = [];
        $json_data['col'] = [];
        //页面信息
        $json_data['page'] = [
            'pageindex' => $_get['page'],
            "pagecount" =>  '0',
            "pagesize" => 0,
        ];
        //类型
        $json_data['type'] = ["id" => $_get['vt'], "title" => '综艺列表'];
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}

/**
 * 影视搜索列表
 * @param string $_wd 搜索内容
 */
function getSoList($_wd)
{
    $url = 'http://json.apibdzy.com/inc/feifei/?wd=' . $_wd;
    $html = LoadOne($url);
    $code = json_decode($html, true);
    // 判断是否采集成功
    if (isset($code['status']) == 200) { //判断指定数据是否存在
        $json_data['code'] = "200";
        $json_data['search'] = $_wd;
        $i = 0;
        foreach ($code['data'] as $key => $value) {
            if ($value['vod_cid'] != 27 && $value['vod_cid'] != 28 && $value['vod_cid'] != 29 && $value['vod_cid'] != 30 && $value['vod_cid'] != 31 && $value['vod_cid'] != 32 && $value['vod_cid'] != 33 && $value['vod_cid'] != 34 && $value['vod_cid'] != 35) {
                $json_data['data'][$i]['id'] = $i + 1;
                $json_data['data'][$i]['vod_pic'] = $value['vod_pic'];
                $kval = base64_encode(urlencode($value['vod_cid'] . '-' . $code['page']['pageindex'] . '-' . $value['vod_id'] . '-' . $_wd));
                $kval = str_replace('=', "", $kval);
                $json_data['data'][$i]['vod_url'] = 'zy/' . $kval . '.html';
                $json_data['data'][$i]['vod_type_id'] = optConvert($value['vod_cid']);
                $json_data['data'][$i]['vod_pay'] = '';
                $json_data['data'][$i]['vod_year'] = $value['vod_year'];
                $json_data['data'][$i]['vod_score'] = '';
                $json_data['data'][$i]['vod_hint'] = $value['vod_continu'];
                $json_data['data'][$i]['vod_title'] = $value['vod_name'];
                $json_data['data'][$i]['vod_actor'] = $value['vod_actor'];
                $json_data['data'][$i]['vod_desc'] = strip_tags($value['vod_content']);
                $i++;
            }
        }

        $json_data['number'] = count($code['data']);
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        //输出JSON数据
        return json_encode($json_data);
    } else {

        //状态
        $json_data['code'] = '204'; //204数据为空
        $json_data['search']  = $_wd;
        //数量
        $json_data['number'] = '0';
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间

        return json_encode($json_data);
    }
}

###########################详情分割线########################################

/**
 * 获取电影信息详情
 * @param [string] $_md5 [电影参数]
 * @param string $_url [地址]
 */
function getDydeta($_md5, $_url = 'http://json.apibdzy.com/inc/feifei/')
{
    $val = urldecode(base64_decode($_md5['sign']));
    $_val = explode('-', $val);
    if (isset($_val[3])) {
        $url = $_url . '?wd=' . $_val[3];
    } else {
        $url = $_url . '?cid=' . $_val[0] . '&p=' . $_val['1'];
    }
    //获取网页源码
    $html = LoadOne($url);
    $code = json_decode($html, true);
    //截取代码关键部分
    if (isset($code['status']) == 200) { //判断指定数据是否存在
        $json_data['data']['id'] = $_md5;
        foreach ($code['data'] as $key => $value) {
            // 取出指定数据
            if ($value['vod_id'] == $_val['2']) {
                $json_data['code'] =  '200'; //状态码
                $json_data['data']['playListType'] =  '1'; //播放列表
                $json_data['data']['playerType'] =  '5'; //播放器类型
                $json_data['data']['vod_pic'] =  $value['vod_pic']; //画报
                $json_data['data']['vod_title'] =  $value['vod_name']; //标题
                $json_data['data']['vod_year'] =  $value['vod_year']; //年份
                $json_data['data']['vod_region'] =  $value['vod_area']; //地区
                $json_data['data']['vod_ranking'] =  ''; //
                $json_data['data']['vod_score'] = ''; //
                $json_data['data']['vod_director'] =  $value['vod_director']; //导演
                $json_data['data']['vod_desc'] =  strip_tags($value['vod_content']); //简介

                // 播放资源
                $playurl = (explode("\n", str_replace("$$$", "\n", $value['vod_url'])));
                // 播放资源类型名称
                $playsign = (explode("\n", str_replace("$$$", "\n", $value['vod_play'])));

                $json_data['data']['play'][0]['vod_sign'] = 'dbm3u8'; //标识
                $json_data['data']['play'][0]['vod_name'] = '百度资源网'; //标题
                $json_data['data']['play'][0]['vip'] = ''; //付费

                foreach ($playurl as $kk => $v) {
                    if (strpos($v, ".m3u8", 0) > 0) {
                        $json_data['data']['play'][0]['data'][$kk]['vod_name'] = substr($v, 0, strpos($v, '$'));
                        $is_urls = substr($v, strpos($v, '$') + 1);
                        $json_data['data']['play'][0]['data'][$kk]['vod_url'] = $is_urls;
                        $json_data['data']['play'][0]['data'][$kk]['vod_sign'] = 'dbm3u8';
                        $json_data['data']['play'][0]['data'][$kk]['vod_time'] = '';
                    }
                }
            }
        }
        $json_data['data']['recommend'] = getRandData($code);
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //204数据为空
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}



/**
 * 获取电视信息详情
 * @param [string] $_md5 [电视参数]
 * @param string $_url [地址]
 */
function getDsdeta($_md5, $_url = 'http://json.apibdzy.com/inc/feifei/')
{
    $val = urldecode(base64_decode($_md5['sign']));
    $_val = explode('-', $val);
    if (isset($_val[3])) {
        $url = $_url . '?wd=' . $_val[3];
    } else {
        $url = $_url . '?cid=' . $_val[0] . '&p=' . $_val['1'];
    }
    // return;
    //获取网页源码
    $html = LoadOne($url);
    $code = json_decode($html, true);
    //截取代码关键部分
    if (isset($code['status']) == 200) { //判断指定数据是否存在
        $json_data['data']['id'] = $_md5;
        foreach ($code['data'] as $key => $value) {
            // 取出指定数据
            if ($value['vod_id'] == $_val['2']) {
                $json_data['code'] =  '200'; //状态码
                $json_data['data']['playListType'] =  '1'; //播放列表
                $json_data['data']['playerType'] =  '5'; //播放器类型
                $json_data['data']['vod_pic'] =  $value['vod_pic']; //画报
                $json_data['data']['vod_title'] =  $value['vod_name']; //标题
                $json_data['data']['vod_year'] =  $value['vod_year']; //年份
                $json_data['data']['vod_region'] =  $value['vod_area']; //地区
                $json_data['data']['vod_ranking'] =  ''; //
                $json_data['data']['vod_score'] = ''; //
                $json_data['data']['vod_director'] =  $value['vod_director']; //导演
                $json_data['data']['vod_desc'] =  strip_tags($value['vod_content']); //简介

                // 播放资源
                $playurl = (explode("\n", str_replace("$$$", "\n", $value['vod_url'])));
                $json_data['data']['play'][0]['vod_sign'] = 'dbm3u8'; //标识
                $json_data['data']['play'][0]['vod_name'] = '百度资源网'; //标题
                $json_data['data']['play'][0]['vip'] = ''; //付费
                // 播放资源类型名称
                foreach ($playurl as $kk => $v) {
                    if (strpos($v, ".m3u8", 0) > 0) {
                        $json_data['data']['play'][0]['data'][$kk]['vod_name'] = substr($v, 0, strpos($v, '$'));
                        $is_urls = substr($v, strpos($v, '$') + 1);
                        $json_data['data']['play'][0]['data'][$kk]['vod_url'] = $is_urls;
                        $json_data['data']['play'][0]['data'][$kk]['vod_sign'] = 'dbm3u8';
                        $json_data['data']['play'][0]['data'][$kk]['vod_time'] = '';
                    }
                }
            }
        }
        $json_data['data']['recommend'] = getRandData($code);
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //204数据为空
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}


/**
 * 获取综艺信息详情
 * @param [string] $_md5 [综艺参数]
 * @param string $_url [地址]
 */
function getZydeta($_md5, $_url = 'http://json.apibdzy.com/inc/feifei/')
{
    $val = urldecode(base64_decode($_md5['sign']));
    $_val = explode('-', $val);
    if (isset($_val[3])) {
        $url = $_url . '?wd=' . $_val[3];
    } else {
        $url = $_url . '?cid=' . $_val[0] . '&p=' . $_val['1'];
    }
    //获取网页源码
    $html = LoadOne($url);
    $code = json_decode($html, true);
    //截取代码关键部分
    if (isset($code['status']) == 200) { //判断指定数据是否存在
        $json_data['data']['id'] = $_md5;
        foreach ($code['data'] as $key => $value) {
            // 取出指定数据
            if ($value['vod_id'] == $_val['2']) {
                $json_data['code'] =  '200'; //状态码
                $json_data['data']['playListType'] =  '1'; //播放列表
                $json_data['data']['playerType'] =  '5'; //播放器类型
                $json_data['data']['vod_pic'] =  $value['vod_pic']; //画报
                $json_data['data']['vod_title'] =  $value['vod_name']; //标题
                $json_data['data']['vod_year'] =  $value['vod_year']; //年份
                $json_data['data']['vod_region'] =  $value['vod_area']; //地区
                $json_data['data']['vod_ranking'] =  ''; //
                $json_data['data']['vod_score'] = ''; //
                $json_data['data']['vod_director'] =  $value['vod_director']; //导演
                $json_data['data']['vod_desc'] =  strip_tags($value['vod_content']); //简介

                // 播放资源
                $playurl = (explode("\n", str_replace("$$$", "\n", $value['vod_url'])));
                $json_data['data']['play'][0]['vod_sign'] = 'dbm3u8'; //标识
                $json_data['data']['play'][0]['vod_name'] = '百度资源网'; //标题
                $json_data['data']['play'][0]['vip'] = ''; //付费
                // 播放资源类型名称
                foreach ($playurl as $kk => $v) {
                    if (strpos($v, ".m3u8", 0) > 0) {
                        $json_data['data']['play'][0]['data'][$kk]['vod_name'] = substr($v, 0, strpos($v, '$'));
                        $is_urls = substr($v, strpos($v, '$') + 1);
                        $json_data['data']['play'][0]['data'][$kk]['vod_url'] = $is_urls;
                        $json_data['data']['play'][0]['data'][$kk]['vod_sign'] = 'dbm3u8';
                        $json_data['data']['play'][0]['data'][$kk]['vod_time'] = '';
                    }
                }
            }
        }
        $json_data['data']['recommend'] = getRandData($code);
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //204数据为空
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}


/**
 * 获取动漫信息详情
 * @param [string] $_md5 [动漫参数]
 * @param string $_url [地址]
 */
function getDmdeta($_md5, $_url = 'http://json.apibdzy.com/inc/feifei/')
{
    $val = urldecode(base64_decode($_md5['sign']));
    $_val = explode('-', $val);
    if (isset($_val[3])) {
        $url = $_url . '?wd=' . $_val[3];
    } else {
        $url = $_url . '?cid=' . $_val[0] . '&p=' . $_val['1'];
    }
    // return;
    //获取网页源码
    $html = LoadOne($url);
    $code = json_decode($html, true);
    //截取代码关键部分
    if (isset($code['status']) == 200) { //判断指定数据是否存在

        $json_data['data']['id'] = $_md5;
        foreach ($code['data'] as $key => $value) {
            // 取出指定数据
            if ($value['vod_id'] == $_val['2']) {
                $json_data['code'] =  '200'; //状态码
                $json_data['data']['playListType'] =  '1'; //播放列表
                $json_data['data']['playerType'] =  '5'; //播放器类型
                $json_data['data']['vod_pic'] =  $value['vod_pic']; //画报
                $json_data['data']['vod_title'] =  $value['vod_name']; //标题
                $json_data['data']['vod_year'] =  $value['vod_year']; //年份
                $json_data['data']['vod_region'] =  $value['vod_area']; //地区
                $json_data['data']['vod_ranking'] =  ''; //
                $json_data['data']['vod_score'] = ''; //
                $json_data['data']['vod_director'] =  $value['vod_director']; //导演
                $json_data['data']['vod_desc'] =  strip_tags($value['vod_content']); //简介

                // 播放资源
                $playurl = (explode("\n", str_replace("$$$", "\n", $value['vod_url'])));
                $json_data['data']['play'][0]['vod_sign'] = 'dbm3u8'; //标识
                $json_data['data']['play'][0]['vod_name'] = '百度资源网'; //标题
                $json_data['data']['play'][0]['vip'] = ''; //付费
                // 播放资源类型名称
                foreach ($playurl as $kk => $v) {
                    if (strpos($v, ".m3u8", 0) > 0) {
                        $json_data['data']['play'][0]['data'][$kk]['vod_name'] = substr($v, 0, strpos($v, '$'));
                        $is_urls = substr($v, strpos($v, '$') + 1);
                        $json_data['data']['play'][0]['data'][$kk]['vod_url'] = $is_urls;
                        $json_data['data']['play'][0]['data'][$kk]['vod_sign'] = 'dbm3u8';
                        $json_data['data']['play'][0]['data'][$kk]['vod_time'] = '';
                    }
                }
            }
        }
        $json_data['data']['recommend'] = getRandData($code);
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    } else {
        //状态
        $json_data['code'] = '404'; //204数据为空
        $endtime = microtime(true);
        $json_data['consume'] = round($endtime - APP_RUN_STARTTIME, 3) . 's'; //页面消耗时间
        return json_encode($json_data);
    }
}


/**
 * 标识值转换
 * @param [string] $val 待转换值
 */
function optConvert($val)
{
    // 电影
    $dy = [5, 6, 7, 8, 9, 10, 11, 16, 17, 18];
    // 判断电影影片类型
    if (in_array($val, $dy)) {
        return 'bddy';
    }
    // 电视
    $ds = [12, 13, 14, 15, 36];
    if (in_array($val, $ds)) {
        return 'bdds';
    }
    //动漫
    $dm = [23, 24, 25, 26];
    if (in_array($val, $dm)) {
        return 'bddm';
    }
    //综艺
    $zy = [19, 20, 21, 22];
    if (in_array($val, $zy)) {
        return 'bdzy';
    }
}

//随机影片数据
function getRandData($data = [])
{
    $json_data = [];
    $code = $data['data'];
    shuffle($code);
    foreach ($code as $key => $value) {
        if ($key < 9) {
            $json_data[$key]['vod_img'] = $value['vod_pic'];
            $kval = base64_encode($value['vod_cid'] . '-' . $data['page']['pageindex'] . '-' . $value['vod_id']);
            $kval = str_replace('=', "", $kval);
            $url =  '/zy/' . $kval . '.html';
            $json_data[$key]['vod_url'] = $url;
            $json_data[$key]['vod_name'] = $value['vod_name'];
        }
    }
    return $json_data;
}
